#ifndef _EXCEPTION_H_
#define _EXCEPTION_H_

#define MASK_DEV_STA  0x0000ffff
#define MASK_CONT_STA  0xffff0000
enum device_status
{
	DEV_STA_OK = 0x01,
	DEV_STA_WRITE_ERR = 0x02,// readonly,IO error
	DEV_STA_INVAL = 0x04, // not exist,not mounted
};

enum content_status
{
	CONT_STA_INIT = 0x00010000,// only write head 
	CONT_STA_WING = 0x00020000,// is writing content,content is not integrity.
	CONT_STA_WEND = 0x00040000,// write content end,content is integrity.
};

struct exception_meta
{
	int chn_id;
	int status;
	char dev_mpoint[64];
	char prev_mpoint[64];
	char fname[64];
	int reserved[4];
};

typedef	int (*device_handle)(const char *dname,int status,void *priv);
typedef	int (*content_handle)(const char *fname,int status,void *priv);
struct exception_handle
{
	device_handle dev_ehdl;
	content_handle cont_ehdl;
};

/**
 * register exception handls and try to fix record files
 *
 * @param[in] ehdl exception handles to register
 * @param[in] devnum device total number to scan for meta data 
 * @param[out] mpoint device mpoint last record to continue record
 * @ret return 0 if find the device ID, or return -1 if fail.
 */
int rsc_exception_init(struct exception_handle *ehdl, int devnum, char *mpoint);

/**
 * RSC exception handle routine: Storage Device Exception and 
 * Record Content Exception handle.
 *
 * For S.D.E: 
 * 	try to restore by the best effort base on don't reboot,
 * 	if cannot restore, we try to reboot system.
 * For R.C.E: 
 * 	only when suddenly power off or write error that cannot fixed
 *  need to fix/handle,we try to fix record files when next reboot 
 *  that is only valid solution.
 */
int rsc_exception_handle(int chn,int status,const char *mpoint,const char *fname);

#endif

